package com.kexio.email.entity;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.kexio.common.entity.BaseEntity;

/**
 * 邮件发送记录
 * 
 * @author Kexio Team
 * @since 1.0.0
 */
@TableName("email_record")
public class EmailRecord extends BaseEntity {
    
    /**
     * 主键ID
     */
    @TableId(value = "id", type = IdType.ASSIGN_ID)
    private String id;
    
    /**
     * 发件人邮箱
     */
    @TableField("from_email")
    private String fromEmail;
    
    /**
     * 发件人名称
     */
    @TableField("from_name")
    private String fromName;
    
    /**
     * 收件人邮箱 (多个用分号分隔)
     */
    @TableField("to_emails")
    private String toEmails;
    
    /**
     * 抄送邮箱 (多个用分号分隔)
     */
    @TableField("cc_emails")
    private String ccEmails;
    
    /**
     * 密送邮箱 (多个用分号分隔)
     */
    @TableField("bcc_emails")
    private String bccEmails;
    
    /**
     * 邮件主题
     */
    @TableField("subject")
    private String subject;
    
    /**
     * 邮件内容 (HTML或文本)
     */
    @TableField("content")
    private String content;
    
    /**
     * 邮件类型 (text, html, template)
     */
    @TableField("email_type")
    private String emailType;
    
    /**
     * 模板ID
     */
    @TableField("template_id")
    private String templateId;
    
    /**
     * 模板参数 (JSON格式)
     */
    @TableField("template_params")
    private String templateParams;
    
    /**
     * 附件信息 (JSON格式)
     */
    @TableField("attachments")
    private String attachments;
    
    /**
     * 发送状态 (pending, sending, success, failed)
     */
    @TableField("status")
    private String status;
    
    /**
     * 发送时间
     */
    @TableField("send_time")
    private LocalDateTime sendTime;
    
    /**
     * 完成时间
     */
    @TableField("complete_time")
    private LocalDateTime completeTime;
    
    /**
     * 错误码
     */
    @TableField("error_code")
    private String errorCode;
    
    /**
     * 错误信息
     */
    @TableField("error_message")
    private String errorMessage;
    
    /**
     * 重试次数
     */
    @TableField("retry_count")
    private Integer retryCount;
    
    /**
     * 最大重试次数
     */
    @TableField("max_retry_count")
    private Integer maxRetryCount;
    
    /**
     * 发送耗时 (毫秒)
     */
    @TableField("duration")
    private Long duration;
    
    /**
     * 优先级 (1-5, 1最高)
     */
    @TableField("priority")
    private Integer priority;
    
    /**
     * 业务类型
     */
    @TableField("business_type")
    private String businessType;
    
    /**
     * 业务关键字
     */
    @TableField("business_key")
    private String businessKey;
    
    /**
     * 是否异步发送
     */
    @TableField("is_async")
    private Boolean isAsync;
    
    // Constructors
    public EmailRecord() {}
    
    public EmailRecord(String toEmails, String subject, String content, String emailType) {
        this.toEmails = toEmails;
        this.subject = subject;
        this.content = content;
        this.emailType = emailType;
        this.status = "pending";
        this.sendTime = LocalDateTime.now();
        this.retryCount = 0;
        this.maxRetryCount = 3;
        this.priority = 3; // 默认中等优先级
        this.isAsync = true;
    }
    
    // Getters and Setters
    public String getId() { return id; }
    public void setId(String id) { this.id = id; }
    
    public String getFromEmail() { return fromEmail; }
    public void setFromEmail(String fromEmail) { this.fromEmail = fromEmail; }
    
    public String getFromName() { return fromName; }
    public void setFromName(String fromName) { this.fromName = fromName; }
    
    public String getToEmails() { return toEmails; }
    public void setToEmails(String toEmails) { this.toEmails = toEmails; }
    
    public String getCcEmails() { return ccEmails; }
    public void setCcEmails(String ccEmails) { this.ccEmails = ccEmails; }
    
    public String getBccEmails() { return bccEmails; }
    public void setBccEmails(String bccEmails) { this.bccEmails = bccEmails; }
    
    public String getSubject() { return subject; }
    public void setSubject(String subject) { this.subject = subject; }
    
    public String getContent() { return content; }
    public void setContent(String content) { this.content = content; }
    
    public String getEmailType() { return emailType; }
    public void setEmailType(String emailType) { this.emailType = emailType; }
    
    public String getTemplateId() { return templateId; }
    public void setTemplateId(String templateId) { this.templateId = templateId; }
    
    public String getTemplateParams() { return templateParams; }
    public void setTemplateParams(String templateParams) { this.templateParams = templateParams; }
    
    public String getAttachments() { return attachments; }
    public void setAttachments(String attachments) { this.attachments = attachments; }
    
    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }
    
    public LocalDateTime getSendTime() { return sendTime; }
    public void setSendTime(LocalDateTime sendTime) { this.sendTime = sendTime; }
    
    public LocalDateTime getCompleteTime() { return completeTime; }
    public void setCompleteTime(LocalDateTime completeTime) { this.completeTime = completeTime; }
    
    public String getErrorCode() { return errorCode; }
    public void setErrorCode(String errorCode) { this.errorCode = errorCode; }
    
    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    
    public Integer getRetryCount() { return retryCount; }
    public void setRetryCount(Integer retryCount) { this.retryCount = retryCount; }
    
    public Integer getMaxRetryCount() { return maxRetryCount; }
    public void setMaxRetryCount(Integer maxRetryCount) { this.maxRetryCount = maxRetryCount; }
    
    public Long getDuration() { return duration; }
    public void setDuration(Long duration) { this.duration = duration; }
    
    public Integer getPriority() { return priority; }
    public void setPriority(Integer priority) { this.priority = priority; }
    
    public String getBusinessType() { return businessType; }
    public void setBusinessType(String businessType) { this.businessType = businessType; }
    
    public String getBusinessKey() { return businessKey; }
    public void setBusinessKey(String businessKey) { this.businessKey = businessKey; }
    
    public Boolean getIsAsync() { return isAsync; }
    public void setIsAsync(Boolean isAsync) { this.isAsync = isAsync; }
}
